<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function arrRank(arr, c) {
        if (c === "+") {
          var t = 0

          for (var j = 0; j < arr.length - 1; j++) {
            for (var i = 0; i < arr.length - 1 - j; i++) {
              if (arr[i] >= arr[i + 1]) {
                //   加减法交换位置有
                t = arr[i] + arr[i + 1]
                arr[i] = t - arr[i]
                arr[i + 1] = t - arr[i]
              }
            }
          }
        } else if (c === "-") {
          var t = 0

          for (var j = 0; j < arr.length - 1; j++) {
            for (var i = 0; i < arr.length - 1 - j; i++) {
              if (arr[i] <= arr[i + 1]) {
                //   加减法交换位置有
                t = arr[i] + arr[i + 1]
                arr[i] = t - arr[i]
                arr[i + 1] = t - arr[i]
              }
            }
          }
        }
        return arr
      }
      var arr = [123, 23, 341, 2341, 43, 23]
      arrRank(arr, "+")
      //   引用
      console.log(arr)
    </script>
  </body>
</html>
